package com.trinity.orders.controller;

import com.trinity.common.annotation.Log;
import com.trinity.common.core.controller.BaseController;
import com.trinity.common.core.domain.AjaxResult;
import com.trinity.common.core.page.TableDataInfo;
import com.trinity.common.enums.BusinessType;
import com.trinity.common.utils.poi.ExcelUtil;
import com.trinity.orders.domain.XcPayRecord;
import com.trinity.orders.service.IXcPayRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 支付记录Controller
 *
 * @author trinity
 * @date 2023-11-19
 */
@RestController
@RequestMapping("/order/record")
public class XcPayRecordController extends BaseController {
    @Resource
    private IXcPayRecordService xcPayRecordService;

    /**
     * 查询支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(XcPayRecord xcPayRecord) {
        startPage();
        List<XcPayRecord> list = xcPayRecordService.selectXcPayRecordList(xcPayRecord);
        return getDataTable(list);
    }

    /**
     * 导出支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:record:export')")
    @Log(title = "支付记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XcPayRecord xcPayRecord) {
        List<XcPayRecord> list = xcPayRecordService.selectXcPayRecordList(xcPayRecord);
        ExcelUtil<XcPayRecord> util = new ExcelUtil<XcPayRecord>(XcPayRecord.class);
        util.exportExcel(response, list, "支付记录数据");
    }

    /**
     * 获取支付记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xcPayRecordService.selectXcPayRecordById(id));
    }

    /**
     * 新增支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:add')")
    @Log(title = "支付记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XcPayRecord xcPayRecord) {
        return toAjax(xcPayRecordService.insertXcPayRecord(xcPayRecord));
    }

    /**
     * 修改支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:edit')")
    @Log(title = "支付记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody XcPayRecord xcPayRecord) {
        return toAjax(xcPayRecordService.updateXcPayRecord(xcPayRecord));
    }

    /**
     * 删除支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:record:remove')")
    @Log(title = "支付记录", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}/delete")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xcPayRecordService.deleteXcPayRecordByIds(ids));
    }
}
